package top.hkyzf.study.leetcode.bit;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-1-31 10:44
 */
public class 将数字变成0的操作次数_1342 {
    public int numberOfSteps(int num) {
        int result = 0;
        while (num > 0) {
            if ((num & 0x01) == 1) {
                num--;
            } else {
                num >>= 1;
            }
            result++;
        }

        /*while (num) {
            result += (num > 1 ? 1 : 0) + (num & 0x01);
            num >>= 1;
        }*/

        return result;
    }

    @Test
    public void testNumberOfSteps () {
        int num = 14;
        System.out.println(numberOfSteps(num));
    }
}
